<template>
  <l-layout class="l-tab-page">
    <l-panel>
      <template #toolLeft >
        <div class="l-panel--item" >
          <el-input :placeholder="$t('请输入要查询关键字')"  @keyup.enter.native="hanleDraftSearch" v-model="searchDraftWord" size="mini" >
            <el-button @click="hanleDraftSearch" slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </div>
      </template>
      <l-table 
        :columns="draftColumns" 
        :dataSource="draftsShowData" 
        :loading="draftsLoading" 
        row-key="f_Id"
        >
        <template v-slot:f_CreateTime="scope" >
          {{lr_dateFormat(scope.row.f_CreateTime)}}
        </template>
        <l-table-btns :btns="draftTableBtns" @click="lr_handleTableBtnClick" ></l-table-btns>
      </l-table>
    </l-panel>
  </l-layout>
</template>
<script>
const apiScheme = window.$api.codetool.scheme

export default {
  data(){
    return {
      lr_isPage:true,
      lr_isAuth:false,
      
      searchDraftWord:'',
      draftsData:[],
      draftsShowData:[],
      draftsLoading:false,
      draftColumns:[
        {label:'名称',prop:'f_Name',minWidth:'150'},
        {label:'时间',prop:'f_CreateTime',minWidth:'150'}
      ],
      draftTableBtns:[
        {prop:'Load',label:'加载'},
        {prop:'DraftDelete',label:'删除'}
      ],
    }
  },
  methods:{
    hanleDraftSearch(){
      if(this.$validatenull(this.searchDraftWord)){
        this.draftsShowData =  this.draftsData
      }
      else{
        this.draftsShowData =  this.draftsData.filter(t=>t.f_Name.indexOf(this.searchDraftWord) != -1)
      }
    },
    handleLoad($index,row){
      this.$emit('load',row)
    },

    handleDraftDelete($index,row){
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
        }).then(async () => {
        this.draftsData.splice($index,1)
        await apiScheme.remove(row.f_Id)
        this.$message({
            type: 'success',
            message: '删除成功!'
        })
      }).catch(() => {
          this.$message({
              type: 'info',
              message: '已取消删除'
          })          
      })
    },
    async loadData(){
      const data = await this.$awaitWraper(apiScheme.getDrafts({f_ProjectId:this.project.f_Id}))
      this.draftsData = data || []
      this.draftsShowData =  this.draftsData
    },
  }
}
</script>
